﻿using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using Kugar.Core.BaseStruct;
using Kugar.Core.Configuration;
using Kugar.ERPFramework.BLLInterface.Session;
using Kugar.ERPFramework.Entity;
using System.ServiceModel;
using Kugar.Core.Data.MSSQLHelper;


namespace Kugar.ERPFramework.BLLInterface
{

    [ServiceContract(Name = "SystemModule")]
    public interface ISystemModule : ICustomBLLModule
    {
        [OperationContract]
        ResultReturn<LoginUserInfo> GetUserInfoByID(int userID);

        [OperationContract]
        ResultReturn<int> Login(string userName, string pw, IPAddress address);

        [OperationContract]
        ResultReturn Logout();

        [OperationContract]
        ResultReturn<string[]> GetUserNameList();

        [OperationContract]
        ResultReturn<LoginUserInfo[]> GetOnlineUser();

        [OperationContract]
        ResultReturn SetUserOffline(int userID);

        [OperationContract]
        ResultReturn SetAllUserOffline();

        [OperationContract]
        ResultReturn<object> GetCurrentPermission();

        [OperationContract]
        ResultReturn<ILoginUserManager> GetUserManager();

        [OperationContract]
        ResultReturn SendMessageToUsers(int userID, string message,int[] revUserIDList);

        [OperationContract]
        ResultReturn SendMessageToAllUser(string message);

        [OperationContract]
        ResultReturn<ICustomConfigSection> GetConfigBySectionName(string sectionName);

        [OperationContract]
        ResultReturn<string> GetSerialNumber(string moduleID);

        [OperationContract]
        ResultReturn UpdateConfig(string sectionName, KeyValuePair<int, string>[] configs);
    }

    [ServiceContract]
    public interface ICustomBLLModule
    {
        string Name { get; }
        ResultReturn Execute(string methodName, params object[] paramList);
        IProjectInstance ProjectInstance { get; }
    }

    [ServiceContract]
    public interface IBussinessModule : ICustomBLLModule
    {
        ISystemModule SystemModule { get; }
    }

    [ServiceContract]
    public interface IProject
    {

        /// <summary>
        ///     返回当前工程的所有项目实例信息列表
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        ProjectInstanceInfo[] GetInstanceList();

        /// <summary>
        ///     根据ID返回项目实例
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [OperationContract]
        IProjectInstance GetInstanceByID(string key);

        /// <summary>
        ///     当前项目中,所有实例的数量
        /// </summary>
        [OperationContract]
        int GetInstanceCount();

        /// <summary>
        ///     新建实例
        /// </summary>
        /// <param name="name">新建实例的名称</param>
        /// <param name="config">实例配置信息</param>
        [OperationContract]
        void NewIntance(string name, object config);

        /// <summary>
        ///     关闭实例,并删除掉该实例的链接
        /// </summary>
        /// <param name="name">关闭实例的名称</param>
        [OperationContract]
        void CloseInstance(string name);

        /// <summary>
        ///     停止一个实例的服务
        /// </summary>
        /// <param name="name"></param>
        [OperationContract]
        void StopInstance(string name);

        /// <summary>
        ///     启动一个实例的服务
        /// </summary>
        /// <param name="name"></param>
        [OperationContract]
        void StartInstance(string name);
    }

    [ServiceContract]
    public interface IProjectInstance
    {
        [OperationContract]
        ResultReturn<ICustomBLLModule> GetModuleByName(string moduleName);

        [OperationContract]
        ResultReturn<T> GetModuleByName<T>(string moduleName) where T:ICustomBLLModule;

        /// <summary>
        ///     返回当前实例的信息
        /// </summary>
        ProjectInstanceInfo InstanceInfo { get; }

        /// <summary>
        ///     执行指定模块的指定函数
        /// </summary>
        /// <param name="moduleID"></param>
        /// <param name="methodID"></param>
        /// <param name="paramList"></param>
        /// <returns></returns>
        [OperationContract]
        ResultReturn Execute(string moduleID, string methodID, params object[] paramList);

        SQLDataHelper CurrentConnection { get; }

        object GetOtherConnection(string connectionName = null);

        SessionItem Session { get; }

        

        //ClientCallContext ClientCallContext { get; }

        IProject Project { get; }
    }

}
